package crudfx.field;
import crudfx.interop.*;
import crudfx.data.*;
import javax.swing.*;
import java.awt.*;
import crudfx.navigation.*;
import java.awt.event.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class StandardLabel extends UIComponent{
    protected var jLabel:JLabel;
    public var icon:javax.swing.Icon on replace{jLabel.setIcon(icon);};
    public var text:String="" on replace{jLabel.setText(text);};
    public var popup:PopUp=null;
    public var leftToRight:Boolean=true on replace{
        if(leftToRight)
            jLabel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT)
            else jLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT );
        };
    function showPopup(e:MouseEvent):Void{
        if(e.isPopupTrigger()){
            if(popup!=null){
                var r:Point = e.getPoint();
                popup.show(this,r.x,r.y);
                }
            }
        }
    init{
        jLabel=new JLabel(text);
        var mouseAdapter:MouseAdapter=MouseAdapter{
            override public function mousePressed(e:MouseEvent):Void{ showPopup(e);}
            override public function mouseReleased(e:MouseEvent):Void{ showPopup(e);}
            }
        jLabel.addMouseListener(mouseAdapter);
        if(leftToRight)
            jLabel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT)
            else jLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT );
        jLabel.setVerticalAlignment(SwingConstants.TOP);
        jLabel.setIcon(icon);
        jLabel.setOpaque(false);
        }
    override public function getJComponent():JComponent{
        return jLabel;
        }
    override public function highlight(s:String):Boolean{
        return false;
        }
    override public function gather():DataTree{
        var me:DataTree=DataTree{ name:"StandardLabel" };
        me.node("text").asString("").value=text;
        return me;
        }
    }

